package com.lq.whattoeattoday.config;


import cn.hutool.json.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 */
@ControllerAdvice // 可指定包前缀，比如：(basePackages = "com.pj.admin")
public class GlobalException
{

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public JSONObject handleException(Exception ex)
	{
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("code", HttpStatus.INTERNAL_SERVER_ERROR.value());
		jsonObject.put("msg", ex.getMessage());
		return jsonObject;
	}


}
